| Conditions | 1 |
| Paths | 1 |
| Total Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('Person', function(){ |
||
| 5 | |||
| 6 | var personJSON = { |
||
| 7 | id: 'testPerson', |
||
| 8 | private: true, |
||
| 9 | living: true, |
||
| 10 | gender: { |
||
| 11 | type: 'http://gedcomx.org/Female' |
||
| 12 | }, |
||
| 13 | names: [ |
||
| 14 | { |
||
| 15 | preferred: true, |
||
| 16 | type: 'http://gedcomx.org/BirthName', |
||
| 17 | nameForms: [ |
||
| 18 | { |
||
| 19 | fullText: 'Joanna Hopkins' |
||
| 20 | } |
||
| 21 | ] |
||
| 22 | } |
||
| 23 | ], |
||
| 24 | facts: [ |
||
| 25 | { |
||
| 26 | type: 'http://gedcomx.org/Birth', |
||
| 27 | date: { |
||
| 28 | formal: '+2001-04-09' |
||
| 29 | }, |
||
| 30 | place: { |
||
| 31 | original: 'Farm house' |
||
| 32 | } |
||
| 33 | } |
||
| 34 | ], |
||
| 35 | display: { |
||
| 36 | "name" : "Joanna Hopkins", |
||
| 37 | "gender" : "Female" |
||
| 38 | } |
||
| 39 | }; |
||
| 40 | |||
| 41 | it('Create with JSON', function(){ |
||
| 42 | var person = GedcomX.Person(personJSON); |
||
| 43 | assert.equal(person.getLiving(), true); |
||
| 44 | assert.equal(person.getId(), 'testPerson'); |
||
| 45 | assert.equal(person.getPrivate(), true); |
||
| 46 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
||
| 47 | assert.equal(person.getPreferredName().getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 48 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 49 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
||
| 50 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
||
| 51 | assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); |
||
| 52 | }); |
||
| 53 | |||
| 54 | it('Build', function(){ |
||
| 55 | var person = GedcomX.Person() |
||
| 56 | .setId('testPerson') |
||
| 57 | .setLiving(true) |
||
| 58 | .setPrivate(true) |
||
| 59 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
||
| 60 | .addName(GedcomX.Name().setPreferred(true).addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
||
| 61 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))) |
||
| 62 | .setDisplay(GedcomX.DisplayProperties().setName("Joanna Hopkins").setGender("Female")); |
||
| 63 | assert.equal(person.getLiving(), true); |
||
| 64 | assert.equal(person.getId(), 'testPerson'); |
||
| 65 | assert.equal(person.getPrivate(), true); |
||
| 66 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
||
| 67 | assert.equal(person.getPreferredName().getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 68 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 69 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
||
| 70 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
||
| 71 | assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); |
||
| 72 | }); |
||
| 73 | |||
| 74 | it('toJSON', function(){ |
||
| 75 | var person = GedcomX.Person(personJSON); |
||
| 76 | assert.deepEqual(person.toJSON(), personJSON); |
||
| 77 | }); |
||
| 78 | |||
| 79 | }); |